<%@ include file="/WEB-INF/views/taglib.jsp" %>
<script type="text/javascript" src="<spring:url value="/resources/js/restrictCharactersForDateInput.js" />"></script>
<h3></h3>
	<form:form id="form" method="post" modelAttribute="report" onsubmit="return beforeSubmit()" cssClass="simpleForm" target="_blank">
		<form:hidden path="reportType" id="reportType" />
		<form:hidden path="module" />
		<form:hidden path="subModule" />
		<form:hidden path="transTypeDesc" id="transTypeDesc"/>
		<div class="clear" style="height:1px">&nbsp;</div>
		<jsp:include page="/WEB-INF/views/message.jsp"></jsp:include>
		
<c:choose>
<c:when test="${report.subModule=='R01'}">
	<jsp:include page="/WEB-INF/views/report/reportParamR01.jsp"></jsp:include>
</c:when>
<c:when test="${report.subModule=='R02'}">
	<jsp:include page="/WEB-INF/views/report/reportParamR02.jsp"></jsp:include>	
</c:when>
<c:when test="${report.subModule=='R03'}">
	<jsp:include page="/WEB-INF/views/report/reportParamR03.jsp"></jsp:include>
</c:when>
<c:when test="${report.subModule=='R04'}">
	<jsp:include page="/WEB-INF/views/report/reportParamR04.jsp"></jsp:include>
</c:when>
</c:choose>	
	  	 
	</form:form>
	<script type="text/javascript">
		$(document).ready(function() {
			cal = Calendar.setup({
		          onSelect: function(cal) { cal.hide() },
		          showTime: false
		    });
			
			if($("#startDate").length > 0){
				cal.manageFields("startBtn", "startDate", globalJsCalDateFormat);
			}
			if($("#endDate").length > 0){
				cal.manageFields("endBtn", "endDate", globalJsCalDateFormat);
			}

		});
		
		function submitExcel()
		{
			$('#reportType').val('XLS');
			$('#form').submit();
		}
		

		function beforeSubmit()
		{

			var start = $("#startDate").val();
			var end = $("#endDate").val();
			var subModule=$("#subModule").val();
			
			if((subModule =="INV01")&&(start.length == 0)){
			    alert("Inventory Valuation Report's start date can't be null!");
				return false;
			}
		
			if(start && end){
				startTime = parseDate(start).getTime();
				endTime = parseDate(end).getTime();
				if(start > end){
					alert("StartDate cannot after EndDate");
					return false;
				}
			}
			
			

			return true;
		}
		
		function submitPdf()
		{
			$('#reportType').val('PDF');
			$('#form').submit();
		}
		
		
		function parseDate(str){  
		  if(typeof str == 'string'){  
		    var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);  
		    if(results && results.length>3)  
		      return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]));   
		    results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);  
		    if(results && results.length>6)  
		      return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]),parseInt(results[4]),parseInt(results[5]),parseInt(results[6]));   
		    results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);  
		    if(results && results.length>7)  
		      return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]),parseInt(results[4]),parseInt(results[5]),parseInt(results[6]),parseInt(results[7]));   
		  }  
		  return null;  
		} 
	</script>